<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>创建多人会诊</title>
    <meta name="viewport"
          content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="stylesheet" href="css/mui.min.css">
    <link rel="stylesheet" type="text/css" href="css/mui.picker.min.css"/>
    <link rel="stylesheet" href="css/grandeHealth.css">
    <style>
			.mui-content{!important; margin-top:-66px}
			.mui-navigate-right:after, .mui-push-right:after {font-size: 26px;}
			.mui-input-group .mui-input-row:after {left: 0;}
			.mui-input-group .tonyli-row{border-bottom: 1px solid #ccc;padding-left: 15px;}			
			.mui-input-group .tonyli-row label{width:40%;line-height: 40px;}
			.mui-input-group .tonyli-row input{width:60%;}				
			#online_details input{font-size: 16px;text-align: right;float: right;margin-right: 10px;line-height: 25px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;}
			.mui-table-view-cell .ccys{
				line-height: 25px;overflow: hidden;display: -webkit-box;-webkit-box-orient: vertical;-webkit-line-clamp: 3;overflow: hidden;color: #333;margin-top: 10px;}
		 	.mui-table-view .mui-media-object{max-width:60px;height: 60px;}
		 	.mui-table-view-cell:after{height: 0;}
			#list li{padding: 11px 10px;}
         	#list li p{width: 60px;text-align: center;}
         	.addReduce{height: 108px;}
			.addReduce img{width:60px;height:60px;}
			.mui-btn.mui-disabled, .mui-btn:disabled, button.mui-disabled, button:disabled, input[type=button].mui-disabled, input[type=button]:disabled, input[type=reset].mui-disabled, input[type=reset]:disabled, input[type=submit].mui-disabled, input[type=submit]:disabled{opacity: 1;}
			#online_details .currentColor{color: #666}
			#list ._stat0,#list ._stat1,#list ._stat2{opacity: 0.5;}






    </style>
</head>
<body>
<!--<header class="mui-bar mui-bar-nav" style="display: block;height: 64px;padding-top:20px">-->
  <!--<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>-->
    <!--<center><label>会诊名称</label></center>-->
  <!--<button id="submit" style="float: right;">保存</button>-->
<!--</header>-->

<div class="mui-content">
    <div class="mui-content-padded" style="margin: 0;">

        <form class="mui-input-group" id="online_details">
            <div class="tonyli-row mui-table-view-cell">
                <a href="javascript:;" class="">
                    <label>会诊名称</label>
                    <input type="text"
                           onkeyup="value=value.replace(/[^\a-\z\A-\Z0-9\u4E00-\u9FA5]/g,'')"
                           id="hzName" name="name" placeholder="请输入多人会诊名称" value=""/>
                </a>
            </div>
            <div class="tonyli-row mui-table-view-cell">
                <a href="javascript:;" class="mui-navigate-right">
                    <label>会诊时间</label>
                    <input type="button" data-options id="hzTime" class="currentColor" name="hzTime"
                           placeholder="" value="请选择时间"/>
                </a>
            </div>
            <div id="patients" class="tonyli-row mui-table-view-cell">
                <a href="javascript:;" class="mui-navigate-right">
                    <label>患者</label>
                    <input type="button" id="patient" placeholder="" value="请选择患者"/>
                </a>
            </div>
            <div id="patientDept" class="tonyli-row mui-table-view-cell">
                <a href="javascript:;" class="mui-navigate-right">
                    <label>患者所属机构</label>
                    <input type="button" id="dept" placeholder="" value="请选择机构（选填）"/>
                </a>
            </div>

            <div id="hzExplains" class="tonyli-row mui-table-view-cell">
                <a href="javascript:;" class="mui-navigate-right">
                    <label>会诊说明</label>
                    <input type="button" id="hzsm" name="hzExplain" class="currentColor"
                           placeholder="" value="请填写说明（选填）"/>
                </a>
                <p id="hzExplain" class="ccys" style="margin-top: 15px;"></p>
            </div>
        </form>

        <div class="tonyli-row mui-table-view-cell">
            <label>会诊医生</label>
        </div>
        <ul id="list" class="mui-row mui-table-view mui-table-view-chevron">
            <li id="addDoc"
                class="addReduce mui-table-view-cell mui-media mui-col-sm-3 mui-col-xs-3">
                <img class="mui-media-object" src="images/add_default.png">
            </li>
            <li id="delDoc"
                class="addReduce mui-table-view-cell mui-media mui-col-sm-3 mui-col-xs-3"
                style="display: none;">
                <img class="mui-media-object" src="images/del_default.png">
            </li>
        </ul>
    </div>
</div>

<script src="js/jquery-1.7.2.min.js"></script>
<script src="js/mui.min.js"></script>
<script src="js/mui.picker.min.js"></script>
<script src="js/grandeHealth.js"></script>
<!--公共js-->
<script src="js/medicalRecord.js"></script>
<!--时间日期选择器-->
<script src="js/dateTime.js"></script>
<script>
			$('#list img[name="_stat3"]').css('border','1px solid red')
			/*
			 *获取缓存数据 
			 */
			var hzName =  window.localStorage.getItem('hzName');//会诊名称
 			var hzTime =  window.localStorage.getItem('hzTime');//会诊时间
 			var patientName =  window.localStorage.getItem('PatientName');//患者名称
			var deptName =  window.localStorage.getItem('deptName');//患者机构名称
	  		var hzsm =  window.localStorage.getItem('hzsm');//会诊说明


				var patientid = window.localStorage.getItem('Patientid');
			function _sgval(a,b,c){
				
				(a == null || a == '') ? $(b).val(c).addClass('currentColor') : $(b).val(a.toString());
			}
			_sgval(hzName,'#hzName','');
			_sgval(hzTime,'#hzTime','请选择时间');
			/*患者名称*/
			_sgval(patientName,'#patient','请选择患者');
			/*患者机构名称*/
			_sgval(deptName,'#dept','请选择机构（选填）');
			_sgval(hzsm,'#hzsm','请填写说明');

			function _sgname(a,b){
				
				(a == null || a == '') ? $(b).attr('name','') : $(b).attr('name',a);
			}
			<!--/*患者编码*-->
			
			function _sghtml(a,b){
				
				(a == null || a == '') ? $(b).html('') : $(b).html(a).siblings('a').find('input').hide();
			}
			
			/*会诊说明*/
			_sghtml(hzsm,'#hzsm');

			try{
 			/*选择患者*/
 			mui("body").on("tap", "#patient", function() {

            try{
                window.localStorage.setItem('hzName',$('#hzName').val()),//会诊名称
                window.localStorage.setItem('hzTime',$('#hzTime').val()),//会诊时间
                window.localStorage.setItem('patientName',$('#patient').val()),//患者名称
                window.localStorage.setItem('deptName',$('#dept').val()),//患者机构名称
                window.localStorage.setItem('hzsm',$('#hzsm').val());//会诊说明
				showpage('choicePatient.html');
            }catch(e){
            alert(e);
            }
			});
 			
 			/*患者所属机构*/
 			mui("body").on("tap", "#patientDept", function() {
 			window.localStorage.setItem('hzName',$('#hzName').val()),//会诊名称
 			window.localStorage.setItem('hzTime',$('#hzTime').val()),//会诊时间
 			window.localStorage.setItem('patientName',$('#patient').val()),//患者名称
			window.localStorage.setItem('deptName',$('#dept').val()),//患者机构名称
	  		window.localStorage.setItem('hzsm',$('#hzsm').val());//会诊说明
				showpage('choiceMechanism.html')
			});

 			var zsGuid = GetLocationParam('zhenShiGuid');//诊室guid
//			zsGuid = "4ea62d03cb8b44b4a4b369ba9acfa345";
			var objDatas = {};
 			/*会诊说明*/
 			mui("body").on("tap", "#hzsm", function() {
 				
 				var hzExplain = $('#hzsm').html();
 				window.localStorage.setItem('hzName',$('#hzName').val()),//会诊名称
 			window.localStorage.setItem('hzTime',$('#hzTime').val()),//会诊时间
 			window.localStorage.setItem('patientName',$('#patient').val()),//患者名称
			window.localStorage.setItem('deptName',$('#dept').val()),//患者机构名称
	  		window.localStorage.setItem('hzsm',$('#hzsm').val());//会诊说明
 				if(hzExplain != ''){
 					showpage('huizhenExplain.html?type='+'001'+'&zsGuid='+zsGuid);
 					window.localStorage.setItem('hzExplain',hzExplain)
 					
 				}else{
 					showpage('huizhenExplain.html')
 				}
			});

             var    dlf;
			if(zsGuid != ''){
				var jbInfo = {
			  		"crossDomain": true,
			  		"url": XHDOC_WEBBASE+'v1/mpc/queryMutilDetail?param='+ zsGuid,
			  		"type": "GET",
			  		"headers": {
				    	"Content-Type": "application/json"
			  		},
			  		"processData": false,
				}
				
				try {
			  	
					$.ajax(jbInfo).done(function (response) {
					
						var result = JSON.parse(response);
						
						try {
						  	
							if(result.code == 000){
								
								if(result.data == ''){
									mui.toast('暂无数据');
								}else{
									dlf=result.data[0];
									$('#name').val(result.data[0].name);//会诊名称
									$('#hzTime').val(result.data[0].dat);//会诊时间
									$('#patient').val(result.data[0].patientname);//患者
									$('#dept').val(result.data[0].deptname);//患者所属机构
									$('#hzExplain').html(result.data[0].note);//会诊说明
									$('#patient').attr('name',result.data[0].patient);//患者编码
									$('#dept').attr('name',result.data[0].dept);//患者所属机构码

									/*判断是否可编辑*/
									if(result.data[0].crtusr != XHDOC_APP_USRID){
										
										$('input').attr('disabled',true);
										$('#patients').removeAttr('id','patients');
										$('#patientDept').removeAttr('id','patientDept');
										$('#addDoc').hide();
										$('#delDoc').hide();
										$('#submit').hide();
									}else{
										$('#submit').removeAttr('id','submit').attr('id','edit'); 
									}
								
						 			var settings = {
								  		"async": false,
								  		"crossDomain": true,
								  		"url": XHDOC_WEBBASE+'v1/mpc/queryMutilBer?refid='+ zsGuid,
								  		"type": "GET",
								  		"headers": {
									    	"Content-Type": "application/json"
								  		},
								  		"processData": false,
									}
									
									$.ajax(settings).done(function (response) {
										
										var objData = JSON.parse(response);
										console.log(objData)
										
										var lisiLi = $('#list li');
		    	
										try {
							  	
										    if(objData.code == 000){

									  			if(objData.data == ''){
									  				mui.toast('暂无邀请医生');
									  				$('#addDoc').show();
									  			}else{
									  				console.log(lisiLi.length)
									  				objDatas = objData.data;
									  				$('#addDoc').show();
									  				$('#delDoc').show();
									  				for(var i = 0; i < objDatas.length; i ++){
									  					var docLi = 
													    '<li class="mui-table-view-cell mui-media mui-col-sm-3 mui-col-xs-3">'+
															'<img class="mui-media-object _stat'+objDatas[i].stat+'" src="'+DOCIMG+objDatas[i].img+'">'+
															'<p class="mui-ellipsis" style="">'+objDatas[i].name+'</p>'+
														'</li>';
											    		$('#list').prepend(docLi);
									  				}
									  				if(objData.data != '' && lisiLi.length == 7){
	
											    		$('#addDoc').hide();
											    	}

									  			}
									  		}
					  
									  	} catch(e) {						    
										    mui.toast('获取数据失败'); 
									  	}
									});
								}
			
						    }else if(data.code == 001){
						    	mui.toast('请求出错'); 
						    }
						    
						} catch(e) {						    
					    	mui.toast('获取数据失败'); 
				  		}
					});
				} catch(e) {
				
				  mui.toast("请检查网络连接");
				
			   	}

			}
            }catch(e){
                alert(e);
            }

 			/*添加医生*/
 			mui("body").on("tap", "#addDoc", function() {
 				showpage('choiceDoc.html');
   				<!--alert('添加医生')-->
			})
 			
 			/*删除医生*/
 			mui("body").on("tap", "#delDoc", function() {
 				
 				<!--alert('删除医生')-->
			})
 			
    		var parameterType = [
	            {
	                "img": "267490CD50B50D69E050AE0AC6849A47",
	                "stat": "1",
	                "ISOL": "0",
	                "sex": "2",
	                "ISTY": "",
	                "BEGOODAT": "擅长心血管疾病康复治疗及脑血管疾病综合康复。",
	                "PB": "",
	                "R": 1,
	                "USRSTAT": "1",
	                "name": "李擎",
	                "guid": "203E4B220B1CF456E050AE0AC684E410",
	                "SORTID": 9999,
	                "id": "1109",
	                "hospital": "上海市徐汇区中心医院",
	                "job": "主治医师",
	                "deptnam": "康复科"
	            }
	        ];

		    /*添加删除医生调取*/
		    function _addDoc(){
		    	
		    	$('#list').html('');
				var addDel = '<li id="addDoc" class="addReduce mui-col-sm-3 mui-col-xs-3">'+
								'<img class="mui-media-object" src="images/add_default.png">'+
							'</li>'+
							'<li id="delDoc" class="addReduce mui-col-sm-3 mui-col-xs-3">'+
								'<img class="mui-media-object" src="images/del_default.png">'+
							'</li>';
		    	$('#list').append(addDel);
		    	for(var i = 0; i < parameterType.length; i ++){
//			    	console.log(parameterType[i])
			    	var docLi = 
					    '<li class="mui-table-view-cell mui-media mui-col-sm-3 mui-col-xs-3">'+
							'<img class="mui-media-object" src="'+DOCIMG+parameterType[i].img+'">'+
							'<p class="mui-ellipsis" style="">'+parameterType[i].name+'</p>'+
						'</li>';
			    	$('#list').prepend(docLi);
			    }
		    	
		    	var lisiLi = $('#list li');
		    	
		    	if(parameterType == '' && lisiLi.length == 2){

		    		$('#delDoc').hide();
		    	}
		    	
		    	if(parameterType != '' && lisiLi.length == 7){
		    		$('#addDoc').hide();
		    	}
		
		    }
		    
		    <!--_addDoc();-->
		    
			
			var newarr = [];
			function _tjInfo(infoUrl,data){
				
				var name = $('#name').val(),//会诊名称
				dat1 = $('#hzTime').val().substr(0,10),//会诊日期
				time = $('#hzTime').val().substr(11,5),//会诊时间
				patient = $('#patient').val(),//患者
				dept = $('#dept').val(),//患者所属机构
				note = $('#hzsm').html();//会诊说明
				 
//				XHDOC_APP_USRNAM = 'zcc';
				var webUrl = infoUrl + '&name='+name+'&patient='+patient
				+'&dept='+dept+'&dat1='+dat1+'&time='+time+'&crtusr='+XHDOC_APP_USRID +'&note='+note;

				if(name == ''){
					mui.toast('会诊名称不可为空')
				}else if($('#hzTime').val() == '请选择时间'){
					mui.toast('会诊时间不可为空')
				}else if(patient == '' || patient == undefined){
					mui.toast('患者不可为空')
				}else if(dept == '' || dept == undefined){
					mui.toast('患者所属机构不可为空');
				}else if(typeof(parameterType) == 'undefined' || parameterType == ''){
					mui.toast('邀请医生不可为空');
				}else{

					try {

						$.ajax({
							url: webUrl,
							type: "POST",
							async:false,
							dataType: "json",
							success: function(result) {
								
								try {
									
									if(result.code == 000){
										
										for(var i = 0; i < parameterType.length; i ++){
											
											parameterType[i].refid = result.data;
											var data = {};
											data['id'] = parameterType[i].id;
											data['name'] = parameterType[i].name;
											data['refid'] = parameterType[i].refid;
											newarr.push(data)
										}
										
									}else{
										mui.toast(result.message)
									}
								} catch(e) {
									mui.toast('获取数据失败')
								}
							},
							error: function(xhr, textStatus, error) {						
								if(textStatus == "error")
								mui.toast('请检查网络连接');
							}					
						});
							
					} catch(e) {
						mui.toast("请检查网络连接");
					}
				}

			}
			/*
			 * 保存
			 */
			<!--mui("body").on("tap", "#submit", -->
			function submit() {
				
				_tjInfo(XHDOC_WEBBASE + 'v1/mpc/createMulti?');
				
				if(newarr != ''){
					
					var settings = {
				  		"async": false,
				  		"crossDomain": true,
				  		"url": XHDOC_WEBBASE + "v1/mpc/adminForJoin",
				  		"type": "POST",
				  		"headers": {
					    	"Content-Type": "application/json"
				  		},
				  		"processData": false,
				  		"data": JSON.stringify(newarr)
					};
					
					$.ajax(settings).done(function (response) {
	
				  		try {
					  		if(JSON.parse(response).code == 000){
					  			
					  			localStorage.removeItem('PatientName');
					  			localStorage.removeItem('deptName');
					  			localStorage.removeItem('hzExplain');
					  			localStorage.removeItem('Dept');
					  			localStorage.removeItem('Patientid');

					  		}
					  	} catch(e) {
							mui.toast('获取数据失败')
						}
						window.android.call('callback','','empty params','finish');
					});
				}
			}
			<!--)-->
			
			/*
			 * 编辑
			 */
			mui("body").on("tap", "#edit", function() {
				
				var arrObj = [];

				if(typeof(parameterType) != 'undefined' || parameterType != ''){
					
					for(var j = 0; j < parameterType.length; j ++){
						arrObj.push({'id':parameterType[j].id,'name':parameterType[j].name})
					}
				}
				for(var i = 0; i < objDatas.length; i ++){
					arrObj.push({'id':objDatas[i].id,'name':objDatas[i].name})
				}
				console.log(arrObj)
				
				var name = $('#name').val(),//会诊名称
				dat1 = $('#hzTime').val().substr(0,10),//会诊日期
				time = $('#hzTime').val().substr(11,5),//会诊时间
				patient = $('#patient').attr('name'),//患者
				dept = $('#dept').attr('name'),//患者所属机构
				note = $('#hzExplain').html();//会诊说明
				
				dlf = {
				   	"guid":zsGuid,
				   	"name":$('#name').val(),
				   	"patient":$('#patient').attr('name'),
				   	"dept":$('#dept').attr('name'),
				   	"dat1":$('#hzTime').val().substr(0,10),
				    "time":$('#hzTime').val().substr(11,5),
				   	"crtusr":XHDOC_APP_USRID,
				   	"note":$('#hzExplain').html(),
		     		"joinmutilvo":arrObj
			   	}
				
				var settings = {
			  		"crossDomain": true,
			  		"url": XHDOC_WEBBASE + 'v1/mpc/updateMutil',
			  		"type": "POST",
			  		"headers": {
				    	"Content-Type": "application/json"
			  		},
			  		"processData": false,
			  		"data": JSON.stringify(dlf)
				};
				
				if(name == ''){
					mui.toast('会诊名称不可为空')
				}else if($('#hzTime').val() == '请选择时间'){
					mui.toast('会诊时间不可为空')
				}else if(patient == '' || patient == undefined){
					mui.toast('患者不可为空')
				}else if(dept == '' || dept == undefined){
					mui.toast('患者所属机构不可为空');
				}else if(arrObj == ''){
					mui.toast('邀请医生不可为空');
				}else{

					try {

						$.ajax(settings).done(function (response) {
							
							if(JSON.parse(response).code == 000){
								mui.toast("修改成功");
							}else{
								mui.toast('该诊室名称已被使用，请重新取名！')
							}
						});
							
					} catch(e) {
						mui.toast("请检查网络连接");
					}
				}
			})






</script>
</body>
</html>


